package org.jsbd.boss.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.jsbd.boss.annotation.SystemControllerLog;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.common.ResponseUtils;
import org.jsbd.boss.dao.IActionTypeDAO;
import org.jsbd.boss.domian.channel.ActionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/actionType")
public class ActionTypeController {
	public static final Logger LOGGER = LoggerFactory.getLogger(ActionTypeController.class);

	@Autowired
	private IActionTypeDAO actionTypeDao;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String configList(Model model) {
		return "actionType/configList";
	}

	// 基本配置查询展示接口
	@RequestMapping(value = "/configList", params = "json")
	@ResponseBody
	public Map<String, Object> configPageList(DataGridModel model) {
		List<ActionType> list = actionTypeDao.selectAll();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rows", list);
		return map;
	}

	// 跳出新增页面
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String addConfig(Model model, HttpServletResponse response) {
		return "actionType/add";
	}

	@ResponseBody
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	@SystemControllerLog(description = "action新增")
	public void saveConfig(ActionType actionType, HttpServletResponse response) {
		actionTypeDao.insertActionType(actionType);
		ResponseUtils.responseSuccess(response);
	}

	@ResponseBody
	@RequestMapping(value = "/delete", method = RequestMethod.GET)
	@SystemControllerLog(description = "action删除")
	public void delete(Integer id, HttpServletResponse response) {
		actionTypeDao.deleteAction(id);
		ResponseUtils.responseSuccess(response);
	}

}
